package com.china08.yxyapi.api.manage.par.office.classnotice;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.mg.YxyNoticeClassRepository;

/**
 * 家长 查某个孩子未读邮件数
 * 
 */
@CrossOrigin
@RestController("ParClassnoticeFindNoReadCountController")
public class ParClassnoticeFindNoReadCountController extends YxyApiBaseController {

    @Autowired
    private YxyNoticeClassRepository yxyNoticeClassRepository;

    @RequestMapping(value = "/api_yw/manage/par/myclass/classnotice/noReadCount", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel precess(HttpServletRequest request, HttpServletResponse response,
            @RequestParam(value = "childId", required = false) String childId,
            @RequestParam(value = "childIds[]", required = false) String[] arrayChildIds) {

        // ###
        int isRead = 0;
        Integer count = 0;
        if (StringUtils.isBlank(childId)) {// 查询所有孩子的邮件未读数量
            List<String> childIds = new ArrayList<String>();
            if (arrayChildIds != null) {
                childIds = Arrays.asList(arrayChildIds);
            }
            count = yxyNoticeClassRepository.countByReceiverUserIdInAndReceiverIsRead(childIds, isRead);
        } else {
            count = yxyNoticeClassRepository.countByReceiverUserIdAndReceiverIsRead(childId, isRead);
        }
        RespModel respModel = new RespModel();
        respModel.count = count;
        return respModel;
    }

    protected static class RespModel extends YxyApiRespModel {
        // 未读数
        public int count;

    }
}